package com.platform.web.controller.system;

import java.util.List;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.platform.common.annotation.Log;
import com.platform.common.core.controller.BaseController;
import com.platform.common.core.domain.AjaxResult;
import com.platform.common.enums.BusinessType;
import com.platform.system.domain.ProCategory;
import com.platform.system.service.IProCategoryService;
import com.platform.common.utils.poi.ExcelUtil;
import com.platform.common.core.page.TableDataInfo;

/**
 * 商品类别Controller
 *
 * @author platform
 * @date 2025-02-23
 */
@Tag(name = "商品类别", description = "")
@RestController
@RequestMapping("/system/category")
public class ProCategoryController extends BaseController {
    @Autowired
    private IProCategoryService proCategoryService;

    /**
     * 查询商品类别列表
     */
    @Operation(summary = "查询商品类别列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(ProCategory proCategory) {
        List<ProCategory> list = proCategoryService.selectProCategoryListAll(proCategory);
        return success(list);
    }

    /**
     * 查询商品类别列表
     */
    @Operation(summary = "查询商品类别列表")
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProCategory proCategory) {
        startPage();
        List<ProCategory> list = proCategoryService.selectProCategoryList(proCategory);
        return getDataTable(list);
    }

    /**
     * 导出商品类别列表
     */
    @Operation(summary = "导出商品类别列表")
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "商品类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProCategory proCategory) {
        List<ProCategory> list = proCategoryService.selectProCategoryList(proCategory);
        ExcelUtil<ProCategory> util = new ExcelUtil<ProCategory>(ProCategory.class);
        util.exportExcel(response, list, "商品类别数据");
    }

    /**
     * 获取商品类别详细信息
     */
    @Operation(summary = "获取商品类别详细信息")
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(proCategoryService.selectProCategoryById(id));
    }

    /**
     * 新增商品类别
     */
    @Operation(summary = "新增商品类别")
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "商品类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProCategory proCategory) {
        proCategory.setUserId(getUserId());
        proCategory.setCreateBy(getUsername());
        return toAjax(proCategoryService.insertProCategory(proCategory));
    }

    /**
     * 修改商品类别
     */
    @Operation(summary = "修改商品类别")
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "商品类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProCategory proCategory) {
        proCategory.setUpdateBy(getUsername());
        return toAjax(proCategoryService.updateProCategory(proCategory));
    }

    /**
     * 删除商品类别
     */
    @Operation(summary = "删除商品类别")
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "商品类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(proCategoryService.deleteProCategoryByIds(ids));
    }
}
